package p270jp.pxv.android.commonUi.view.segmentedControl;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import com.google.android.gms.common.internal.ServiceSpecificExtraArgs;
import com.google.android.material.textview.MaterialTextView;
import p045be.View$OnClickListenerC1102r;
import p047bg.C1124a;
import p189gn.AbstractC3446l;
import p307l9.MaterialShapeDrawable;
import p307l9.ShapeAppearanceModel;
import p325m0.MutabilityOwnership;
import p603wm.Unit;

/* compiled from: PixivSegmentedLayout.kt */
/* renamed from: jp.pxv.android.commonUi.view.segmentedControl.PixivSegmentedLayout */
/* loaded from: classes2.dex */
public final class PixivSegmentedLayout extends LinearLayout {

    /* renamed from: i */
    public static final /* synthetic */ int f18970i = 0;

    /* renamed from: a */
    public final int f18971a;

    /* renamed from: b */
    public final int f18972b;

    /* renamed from: c */
    public final int f18973c;

    /* renamed from: d */
    public final ColorStateList f18974d;

    /* renamed from: e */
    public final int f18975e;

    /* renamed from: f */
    public final int f18976f;

    /* renamed from: g */
    public String[] f18977g;

    /* renamed from: h */
    public AbstractC3446l<? super Integer, Unit> f18978h;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public PixivSegmentedLayout(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0, 2131887297);
        int i;
        MutabilityOwnership.m3745m(context, "context");
        this.f18977g = new String[0];
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C1124a.f5009a, 0, 2131887297);
        this.f18971a = obtainStyledAttributes.getDimensionPixelSize(1, 0);
        this.f18972b = obtainStyledAttributes.getDimensionPixelSize(0, 0);
        ColorStateList colorStateList = context.getColorStateList(obtainStyledAttributes.getResourceId(6, 0));
        MutabilityOwnership.m3746l(colorStateList, "context.getColorStateList(itemTextColorRes)");
        this.f18974d = colorStateList;
        this.f18973c = obtainStyledAttributes.getColor(2, 0);
        this.f18975e = obtainStyledAttributes.getResourceId(3, 2131886505);
        this.f18976f = obtainStyledAttributes.getResourceId(4, 0);
        int resourceId = obtainStyledAttributes.getResourceId(5, 0);
        if (resourceId != 0) {
            String[] stringArray = context.getResources().getStringArray(resourceId);
            MutabilityOwnership.m3746l(stringArray, "{\n                contex…ayResource)\n            }");
            this.f18977g = stringArray;
            obtainStyledAttributes.recycle();
            String[] strArr = this.f18977g;
            int length = strArr.length;
            int i2 = 0;
            int i3 = 0;
            while (i2 < length) {
                String str = strArr[i2];
                int i4 = i3 + 1;
                MaterialTextView materialTextView = new MaterialTextView(getContext(), null);
                materialTextView.setText(str);
                materialTextView.setTextColor(this.f18974d);
                materialTextView.setTextAppearance(this.f18976f);
                MaterialShapeDrawable fVar = new MaterialShapeDrawable(ShapeAppearanceModel.m3883a(getContext(), this.f18975e, 0).m3876a());
                fVar.m3893q(ColorStateList.valueOf(this.f18973c));
                StateListDrawable stateListDrawable = new StateListDrawable();
                stateListDrawable.addState(new int[]{16843518}, fVar);
                materialTextView.setBackground(stateListDrawable);
                materialTextView.setGravity(17);
                materialTextView.setOnClickListener(new View$OnClickListenerC1102r(materialTextView, this, i3, 1));
                boolean z = i3 != 0;
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, this.f18972b);
                layoutParams.weight = 1.0f;
                if (z) {
                    i = 0;
                } else {
                    i = this.f18971a;
                }
                layoutParams.rightMargin = i;
                materialTextView.setLayoutParams(layoutParams);
                materialTextView.setActivated(!z);
                addView(materialTextView);
                i2++;
                i3 = i4;
            }
            return;
        }
        throw new IllegalStateException("レイアウトxmlにて app:itemLabelArray を指定してください");
    }

    public final void setOnChangeSelectItemListener(AbstractC3446l<? super Integer, Unit> lVar) {
        MutabilityOwnership.m3745m(lVar, ServiceSpecificExtraArgs.CastExtraArgs.LISTENER);
        this.f18978h = lVar;
    }
}
